package com.zpdhy.service.impl;

import com.zpdhy.service.BaseService;
import org.springframework.data.repository.CrudRepository;

import java.io.Serializable;

/**
 * Created by kedong on 2016/12/31.
 */
public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {

    private CrudRepository<T, ID> repository;

    public void setRepository(CrudRepository<T, ID> repository) {
        this.repository = repository;
    }

    @Override
    public <S extends T> S save(S entity) {
        return repository.save(entity);
    }

    @Override
    public <S extends T> Iterable<S> save(Iterable<S> entities) {
        return repository.save(entities);
    }

    @Override
    public T findOne(ID id) {
        return repository.findOne(id);
    }

    @Override
    public boolean exists(ID id) {
        return repository.exists(id);
    }

    @Override
    public Iterable<T> findAll() {
        return repository.findAll();
    }

    @Override
    public Iterable<T> findAll(Iterable<ID> ids) {
        return repository.findAll(ids);
    }

    @Override
    public long count() {
        return repository.count();
    }

    @Override
    public void delete(ID id) {
        repository.delete(id);
    }

    @Override
    public void delete(T entity) {
        repository.delete(entity);
    }

    @Override
    public void delete(Iterable<? extends T> entities) {
        repository.delete(entities);
    }

    @Override
    public void deleteAll() {
        repository.deleteAll();
    }
}
